﻿/*
 * KLF Headless Browser
 * Written by Kris Oye <kristianoye@gmail.com>
 * Copyright (C) 2011-2012.  All rights reserved.
 */
namespace KLF.Lib.Browser.DOM
{
    #region Using Statements

    using System.Collections.Generic;

    #endregion

    public class DOMStringList
    {
        #region Properties

        internal List<string> Strings { get; set; }

        #endregion

        #region Constructors

        public DOMStringList(List<string> _strings)
        {
            Strings = _strings;
        }

        #endregion

        #region DOM Level 3 Compliance

        /// <summary>
        /// Test if a string is part of this DOMStringList.
        /// </summary>
        /// <param name="str">The string to look for.</param>
        /// <returns>true if the string has been found, false otherwise.</returns>
        public bool contains(string str)
        {
            return Strings.Contains(str);
        }

        /// <summary>
        /// Returns the indexth item in the collection. If index is greater 
        /// than or equal to the number of DOMStrings in the list, this 
        /// returns null. 
        /// </summary>
        /// <param name="index">Index into the collection.</param>
        /// <returns>The DOMString at the indexth position in the 
        /// DOMStringList, or null if that is not a valid index</returns>
        public string item(int index)
        {
            return (index > -1 && index < Strings.Count ? Strings[index] : null);

        }

        /// <summary>
        /// Returns the number of strings in the list.
        /// 
        /// The range of valid child node indices is 0 to length-1 inclusive.
        /// </summary>
        public int length { get { return Strings.Count; } }

        #endregion
    }
}
